﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.IO;
using System.Windows.Input;
using JmShared;
using System.Text.RegularExpressions;
using JiveMessenger.Utilities;
using JiveMessenger.Models;
using System.Windows.Media;
using JiveMessenger.ViewModels;

namespace JiveMessenger
{
    public class ProgramSettings
    {
        private static object _lockObject = new object();

        private static ProgramSettings _instance;
        public static ProgramSettings Instance
        {
            get
            {
                lock (_lockObject)
                {
                    if (_instance == null)
                        _instance = new ProgramSettings();
                }
                return _instance;
            }
        }

        private ProgramSettings()
        {

        }


#if DEBUG
        public string DataFolder = StaticMethods.CombinePath(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.Current.GetType().Assembly.GetName().Name+"-debug");
#else
        public string DataFolder = StaticMethods.CombinePath(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.Current.GetType().Assembly.GetName().Name);
#endif
        public Regex HyperLinkRegex = new Regex(@"(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-ZÆæÅåØø0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[\S]*)?");

        public string AvatarFolder
        {
            get
            {
                return StaticMethods.CombinePath(DataFolder, "Avatars");
            }
        }

        public string CustomEmoticonFolder
        {
            get { return StaticMethods.CombinePath(DataFolder, "CustomEmoticons"); }
        }
        public string CustomContactEmoticonFolder
        {
            get { return StaticMethods.CombinePath(DataFolder, "Custom_Contact_Emoticons"); }
        }
        public string LogFolder
        {
            get { return StaticMethods.CombinePath(DataFolder, "Logs"); }
        }
        public string ErrorLogFolder
        {
            get { return StaticMethods.CombinePath(DataFolder, "Error Logs"); }
        }

        public bool HasTouchInput()
        {
            return Tablet.TabletDevices.Cast<TabletDevice>().Any(tabletDevice => tabletDevice.Type == TabletDeviceType.Touch);
        }

        public Dictionary<string, ContactListState> ContactListState { get; set; }

        public bool JustUpdated { get; set; }

        public int ServerPort
        {
#if DEBUG
            get { return 8080; }
#else
            get { return 8080; }
#endif
        }

        public int LastConversationLogMessageCount
        {
            get { return 5; }
        }

        public int MaxLinesPerDocument
        {
            get { return 5000; }
        }

        private Dictionary<string[], string> _defaultEmoticons;
        public Dictionary<string[], string> DefaultEmoticons
        {
            get { return _defaultEmoticons ?? (_defaultEmoticons = MakeDefaultEmoticonList()); }
        }
        private Dictionary<string[], string> MakeDefaultEmoticonList()
        {
            Dictionary<string[], string> defaultEmoticons = new Dictionary<string[], string>
                {
                    {new[]{":)",":-)"}, "Smile.png"},
                    {new[]{":D",":-D"}, "Open_mouthed.png"},
                    {new[]{";)",";-)"}, "Wink_smile.png"},
                    {new[]{":O",":-O"}, "Surprised.png"},
                    {new[]{":P"}, "Tongue_out.png"},
                    {new[]{"(H)"}, "hot.png"},
                    {new[]{":@"}, "Angry.png"},
                    {new[]{":S",":-S"}, "Confused.png"},
                    {new[]{":$"}, "Embarrassed.png"},
                    {new[]{":(",":-("}, "Sad.png"},
                    {new[]{":'("}, "Crying.gif"},
                    {new[]{":|"}, "Disappointed.png"},
                    {new[]{"(A)"}, "Angel.png"},
                    {new[]{"8o|"}, "Baring_teeth.png"},
                    {new[]{"8-|"}, "Nerd.png"},
                    {new[]{"+o("}, "Sick.png"},
                    {new[]{"|-)"}, "Sleepy.gif"},
                    {new[]{"<:o)"}, "Party.gif"},
                    {new[]{":^)"}, "I_dont_know.png"},
                    {new[]{":-#"}, "Not_Telling.png"},
                    {new[]{":-*"}, "Secret_telling.png"},
                    {new[]{"^o)"}, "Sarcastic.png"},
                    {new[]{"8-)"}, "Eye_rolling.gif"},
                    {new[]{"(L)"}, "Red_heart.png"},
                    {new[]{"(U)"}, "Broken_heart.png"},
                    {new[]{"({)"}, "Left_hug.png"},
                    {new[]{"(})"}, "Right_hug.png"},
                    {new[]{"(bah)"}, "Sheep.png"},
                    {new[]{"*-)"}, "Thinking.gif"},
                    {new[]{"(B)"}, "Beer.png"},
                    {new[]{"(@)"}, "Cat.png"},
                    {new[]{"(D)"}, "Cocktail.png"},
                    {new[]{"(C)"}, "Coffee.png"},
                    {new[]{"(6)"}, "Devil.png"}
                };

            return defaultEmoticons;
        }

    }
}
